package serova.valeriya.electricity;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

public class TarificationRule {
	private static final Logger LOGGER = Logger.getLogger(TarificationRule.class);
	
	private String category;
	private List<Integer> threshold = new ArrayList<Integer>();
	private List<Double> rate = new ArrayList<Double>();

	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public List<Integer> getThreshold() {
		return threshold;
	}

	public void setThreshold(List <Integer> threshold) {
		this.threshold = threshold;
	}

	public List<Double> getRate() {
		return rate;
	}

	public void setRate(List<Double> rate) {
		this.rate = rate;
	}

	public double chooseTarif(int electricity) {
		int limitIndex = -1;
		try {
			for (int i = 0; i < threshold.size()
					&& (electricity > threshold.get(i)); i++) {
				limitIndex = i;
			}

		} catch (IndexOutOfBoundsException s) {
			LOGGER.error("Ошибка источника данных. Тариф не найден", s);
			UserDialog.printReport("Ошибка источника данных. Тариф не найден");
		}
		return rate.get(limitIndex + 1);
	}
}
